////（2）定义一个测试类ArrayListDemo，
//// 在该类中先创建ArrayList<Student>集合班级对象smallArray1，
//// 添加以下学生类Student的对象元素如下：
////Student("貂蝉", 19);
////Student("大乔", 23);
////Student("小乔", 18);
////Student("孙尚香", 26)；
////（3）创建ArrayList<Student>集合对象班级smallArray2，
//// 添加以下学生类Student的对象元素如下：
////Student("孙二娘", 25);
////Student("扈三娘", 27);
////Student("李师师", 17);
////Student("阎婆惜", 36);
////（4）创建ArrayList<Student>集合对象班级smallArray3，
//// 添加以下学生类Student的对象元素如下：
////Student("林黛玉", 19);
////Student("王熙凤", 35);
////Student("薛宝钗", 20);
////Student("袭人", 21);
////（5）创建ArrayList<ArrayList<Student>>集合对象年级bigArray，
//// 将班级对象smallArray1、smallArray2、smallArray3添加到年级集合bigArray
////（6）分别使用增强for形式和JDK8的forEach方式嵌套遍历输出班级学生信息。

package Javacode_4;

import com.sun.deploy.security.BadCertificateDialog;

import java.util.ArrayList;

public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList<Student> smallArray1=new ArrayList<>();
        smallArray1.add(new Student("貂蝉", 19));
        smallArray1.add(new Student("大乔", 23));
        smallArray1.add(new Student("小乔", 18));
        smallArray1.add(new Student("孙尚香", 26));

        ArrayList<Student> smallArray2=new ArrayList<>();
        smallArray2.add(new Student("孙二娘",25));
        smallArray2.add(new Student("扈三娘",27));
        smallArray2.add(new Student("李师师", 17));
        smallArray2.add(new Student("阎婆惜", 36));

        ArrayList<Student> smallArray3=new ArrayList<>();
        smallArray3.add(new Student("林黛玉", 19));
        smallArray3.add(new Student("王熙凤", 35));
        smallArray3.add(new Student("薛宝钗", 20));
        smallArray3.add(new Student("袭人", 21));

        ArrayList<ArrayList<Student>> bigArray=new ArrayList<>();
        bigArray.add(smallArray1);
        bigArray.add(smallArray2);
        bigArray.add(smallArray3);

        System.out.println("===== 使用增强for循环遍历 =====");
        final int[] classIndex = {1};
        for (ArrayList<Student> clazz : bigArray) {
            System.out.println("班级" + classIndex[0] + "的学生信息：");
            for (Student student : clazz) {
                System.out.println(student);
            }
            classIndex[0]++;
            System.out.println(); // 班级之间空一行
        }


        System.out.println("===== 使用JDK8 forEach遍历 =====");
        classIndex[0] = 1;
        bigArray.forEach(clazz -> {
            System.out.println("班级" + classIndex[0] + "的学生信息：");
            clazz.forEach(student -> System.out.println(student));
            classIndex[0]++;
            System.out.println(); // 班级之间空一行
        });

    }

}
